package com.ruoyi.monitor.controller;



import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.monitor.dao.entity.CameraInfo;
import com.ruoyi.monitor.dto.req.CameraInfoQueryReqDTO;
import com.ruoyi.monitor.service.CameraInfoService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 项目描述
 * @author：cc
 * @date: 2024/7/25
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mon/camera_info")
public class CameraInfoController {

    private final CameraInfoService cameraInfoService;

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询摄像头详情")
    public AjaxResult detail(@PathVariable Long id) {
        CameraInfo cameraInfo = cameraInfoService.queryById(id);
        return AjaxResult.success(cameraInfo);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表查询", notes = "提供给监控页面使用")
    public AjaxResult list(CameraInfoQueryReqDTO req, Pageable page) {
        // 提供给监控页面, 用于搜索需要监控的摄像头
        List<CameraInfo> list = cameraInfoService.queryList(req, page);
        return AjaxResult.success(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @PostMapping("/add")
    @ApiOperation("添加摄像头")
    public AjaxResult add(@RequestBody CameraInfo cameraInfo) {
        int res = cameraInfoService.create(cameraInfo);
        return AjaxResult.success(res);
    }

    @PostMapping("/edit")
    @ApiOperation("编辑设备信息")
    public AjaxResult edit(@RequestBody CameraInfo cameraInfo) {
        int res = cameraInfoService.update(cameraInfo);
        return AjaxResult.success(res);
    }

    @PostMapping("/remove/{id}")
    @ApiOperation("删除设备")
    public AjaxResult remove(@PathVariable Long id) {
        int res = cameraInfoService.remove(id);
        return AjaxResult.success(res);
    }

}
